﻿#include "LampControl/LightToolBar.h"

namespace Qly {

LightToolBar::LightToolBar(QWidget *parent)
    :QToolBar(parent)
{
    initContent();
    initConnection();
}

void LightToolBar::attach(LampControl *control)
{
    m_control = control;
}

void LightToolBar::initContent()
{
    checkBoxTop = new QCheckBox(this);
    checkBoxTop->setObjectName(QString::fromUtf8("checkBoxTop"));
    checkBoxTop->setText(tr (u8"上光源"));

    addWidget(checkBoxTop);

   horizontalSliderTop = new QSlider(this);
   horizontalSliderTop->setObjectName(QString::fromUtf8("horizontalSliderTop"));
   horizontalSliderTop->setMinimumWidth(255);
   horizontalSliderTop->setMaximumWidth(255);
   horizontalSliderTop->setRange(0, 255);
   horizontalSliderTop->setOrientation(Qt::Horizontal);

   addWidget(horizontalSliderTop);

   labelValueTop = new QLabel(this);
   labelValueTop->setObjectName(QString::fromUtf8("labelValueTop"));
   labelValueTop->setMinimumSize(QSize(50, 0));
//   labelValueTop->setMaximumSize(QSize(50, 50));
   labelValueTop->setFrameShape(QFrame::Box);

   addWidget(labelValueTop);


   addSeparator();
   addSeparator();


   checkBoxBottom = new QCheckBox(this);
   checkBoxBottom->setObjectName(QString::fromUtf8("checkBoxBottom"));
   checkBoxBottom->setText(tr (u8"下光源"));

   addWidget(checkBoxBottom);

   horizontalSliderBottom = new QSlider(this);
   horizontalSliderBottom->setObjectName(QString::fromUtf8("horizontalSliderBottom"));
   horizontalSliderBottom->setRange(0, 255);
   horizontalSliderBottom->setMaximumWidth(255);
   horizontalSliderBottom->setMinimumWidth(255);
   horizontalSliderBottom->setOrientation(Qt::Horizontal);

   addWidget(horizontalSliderBottom);

   labelValueBottom = new QLabel(this);
   labelValueBottom->setObjectName(QString::fromUtf8("labelValueBottom"));
   labelValueBottom->setMinimumSize(QSize(50, 0));
   labelValueBottom->setFrameShape(QFrame::Box);

   addWidget(labelValueBottom);
}

void LightToolBar::initConnection()
{

    labelValueTop->setNum(horizontalSliderTop->value());
    labelValueBottom->setNum(horizontalSliderBottom->value());

    connect(horizontalSliderTop, &QSlider::valueChanged, this, &LightToolBar::on_horizontalSliderTop_valueChanged);
    connect(horizontalSliderBottom, &QSlider::valueChanged, this, &LightToolBar::on_horizontalSliderBottom_valueChanged);

}

void LightToolBar::on_horizontalSliderTop_valueChanged(int value)
{
    labelValueTop->setNum(value);
    if(m_control)
    {
        m_control->setValue(0, value);
    }
}

void LightToolBar::on_horizontalSliderBottom_valueChanged(int value)
{
    labelValueBottom->setNum(value);
    if(m_control)
    {
        m_control->setValue(1, value);
    }
}

}
